﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace TreeListView.WPF.Model
{
    public class HierarchicalDocumentItem
    {
        public Guid ID { get; set; }
        public Guid ParentID { get; set; }
        public Guid DocumentID { get; set; }
        public int Number { get; set; }
        public string Description { get; set; }
        private IEnumerable<DocumentItem> itemsSource;

        public HierarchicalDocumentItem(Guid id, Guid parentID, int number, string description, IEnumerable<DocumentItem> itemsSource)
        {
            this.ID = id;
            this.ParentID = parentID;
            this.Number = number;
            this.itemsSource = itemsSource;
        }


        public ObservableCollection<HierarchicalDocumentItem> _items;
        public ObservableCollection<HierarchicalDocumentItem> Items
        {
            get
            {
                if (_items == null)
                {
                    var v = from x in this.itemsSource where x.ParentID == ID select new HierarchicalDocumentItem(x.ID,x.ParentID,x.Number,x.Description,itemsSource);
                    _items = new ObservableCollection<HierarchicalDocumentItem>(v);
                }

                return _items;
            }
        }
    }
}
